<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * Zend_Calendar
 *
 * @category   Zend
 * @package    Zend_Dojo_View_Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Dojo_View_Helper_Dojo_Extended extends Zend_Dojo_View_Helper_Dojo
{
	const DECLARATIVE = 'declarative';
	const PROGRAMMATIC = 'programmatic';
	const PROGRAMMATIC_NOSCRIPT = 'programmatic_noscript';
	
	/**
	 * Holds the base path for stylesheets
	 */
	protected static $_stylesheetBasePath = null;
	
	public static function getDojo()
	{
		$dojo = new Zend_Dojo_View_Helper_Dojo();
		return $dojo->dojo();
	}
	
	/**
	 * Static setter for stylesheet base
	 * 
	 * @param string $basePath
	 */
	public static function setStylesheetBasePath($basePath = null)
	{
		if (null === $basePath) {
			if (self::getDojo()->useLocalPath()) {
				$basePath = self::getDojo()->getLocalPath();
			} else {
				$basePath = self::getDojo()->getCdnBase() . self::getDojo()->getCdnVersion();
			}
		}
		
		self::$_stylesheetBasePath = $basePath;
	}
	
	/**
	 * Static getter for stylesheet base path
	 * 
	 * @return string
	 */
	public static function getStylesheetBasePath()
	{
		// Determine path to use
		if (null === self::$_stylesheetBasePath) {
			self::setStylesheetBasePath();
		}
		
		return self::$_stylesheetBasePath;
	}
	
	/**
	 * Adds a stylesheet based on the dojo path (local or cdn). 
	 * Method is static for situations where you need the stylesheets 
	 * to render even if even the dijits haven't been called but
	 * will during execution (AJAX calls).
	 * 
	 * @param string $stylesheet Path to stylesheet from base path.
	 */
	public static function addStylesheet($path)
	{
		self::getDojo()->addStylesheet(self::getStylesheetBasePath() . $path);
	}
	
	/**
	 * Returns the current render type
	 */
	public static function getRenderType()
	{
		if (self::useDeclarative()) {
			return self::DECLARATIVE;
		}
		
		if (self::useProgrammaticNoScript()) {
			return self::PROGRAMMATIC_NOSCRIPT;
		}
		
		return self::PROGRAMMATIC;
	}
	
	/**
	 * Sets the render type
	 * @param string $render
	 */
	public static function setRenderType($render)
	{
		switch ($render) {
			case self::PROGRAMMATIC:
				self::setUseProgrammatic();
				break;
			case self::PROGRAMMATIC_NOSCRIPT:
				self::setUseProgrammatic(-1);
				break;
			default:
				self::setUseDeclarative();
				break;
		}
	}
}